package com.invengo.library_rfid.analyze.utils.uhf.utils;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Random;
import java.security.SecureRandom;

public class Test1111 {


    private static int getRandomSeed() {
        SecureRandom rng = new SecureRandom();
        byte[] bytes = new byte[4];
        rng.nextBytes(bytes);
        return java.nio.ByteBuffer.wrap(bytes).getInt();
    }

    private static long bookIDSwitch_FDDX(String szBarCode) {
        long lEPCOrder = 0;
        try {
            if (szBarCode.length() == 14) {
                if (szBarCode.substring(0, 1).toUpperCase().equals("B")
                        || szBarCode.substring(0, 1).toUpperCase().equals("J")
                        || szBarCode.substring(0, 1).equals("1")) {
                    Random objRandom = new Random(getRandomSeed());
                    lEPCOrder = Long.parseLong(LocalDate.now().format(DateTimeFormatter.ofPattern("MMdd")) + String.format("%08d", objRandom.nextInt(99999999) + 1));
                    return lEPCOrder;
                } else {
                    return 0;
                }
            } else if (szBarCode.length() == 8 || szBarCode.length() == 9) {
                if (szBarCode.substring(0, 1).toUpperCase().equals("C")
                        || szBarCode.substring(0, 1).toUpperCase().equals("E")) {
                    Random objRandom = new Random(getRandomSeed());
                    lEPCOrder = Long.parseLong(LocalDate.now().format(DateTimeFormatter.ofPattern("MMdd")) + String.format("%08d", objRandom.nextInt(99999999) + 1));
                    return lEPCOrder;
                } else {
                    return 0;
                }
            } else {
                return 0;
            }
        } catch (Exception e) {
            return 0;
        }
    }

    private static long bookIDSwitch_TZLib(String szBarCode) {
        try {
            if (szBarCode.length() != 14) {
                return 0;
            }
            // Assuming ZHENGZBDS.IsValidString is a method to validate the string. This needs to be implemented in Java.
            // if (!ZHENGZBDS.isValidString(szBarCode, ZHENGZBDS.ZZValidNumber)) {
            //     return 0;
            // }
            Random objRandom = new Random(getRandomSeed());
            long lEPCOrder = Long.parseLong(LocalDate.now().format(DateTimeFormatter.ofPattern("MMdd")) + String.format("%08d", objRandom.nextInt(99999999) + 1));
            return lEPCOrder;
        } catch (Exception e) {
            return 0;
        }
    }

    private static long bookIDSwitch_XNDXLib(String szBarCode) {
        Random objRandom = new Random(getRandomSeed());
        long lEPCOrder = Long.parseLong(LocalDate.now().format(DateTimeFormatter.ofPattern("MMdd")) + String.format("%08d", objRandom.nextInt(99999999) + 1));
        return lEPCOrder;
    }

    private static long bookIDSwitch_XBNLKJDXLib(String szBarCode) {
        try {
            if (szBarCode.length() == 5 || szBarCode.length() == 6 || szBarCode.length() == 7 || szBarCode.length() == 9) {
                // Assuming ZHENGZBDS.IsValidString is a method to validate the string. This needs to be implemented in Java.
                // if (ZHENGZBDS.isValidString(szBarCode, ZHENGZBDS.ZZValidNumber)) {
                Random objRandom = new Random(getRandomSeed());
                long lEPCOrder = Long.parseLong(LocalDate.now().format(DateTimeFormatter.ofPattern("MMdd")) + String.format("%08d", objRandom.nextInt(99999999) + 1));
                return lEPCOrder;
                // } else if (ZHENGZBDS.isValidString(szBarCode.substring(2), ZHENGZBDS.ZZValidNumber) &&
                //         !ZHENGZBDS.isValidString(szBarCode.substring(0, 2), ZHENGZBDS.ZZValidNumber)) {
                //     long lEPCOrder = Long.parseLong(LocalDate.now().format(DateTimeFormatter.ofPattern("MMdd")) + szBarCode.substring(2));
                //     return lEPCOrder;
                // } else {
                //     return 0;
                // }
            } else {
                return 0;
            }
        } catch (Exception e) {
            return 0;
        }
    }

    private static long bookIDSwitch_TYLGLib(String szBarCode) {
        try {
            if (szBarCode.length() == 9 || szBarCode.length() == 10 || szBarCode.length() == 11 || szBarCode.length() == 12) {
                Random objRandom = new Random(getRandomSeed());
                long lEPCOrder = Long.parseLong(LocalDate.now().format(DateTimeFormatter.ofPattern("MMdd")) + String.format("%08d", objRandom.nextInt(99999999) + 1));
                return lEPCOrder;
            } else {
                return 0;
            }
        } catch (Exception e) {
            return 0;
        }
    }



}
